package com.hzit.controller;

import com.hzit.client.StudentClient;
import com.hzit.entity.Emp;
import com.hzit.service.EmpService;
import com.hzit.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 作者：李嘉浩
 * 时间：2024-08-21-19:48
 * 功能：
 */

@RestController
@RequestMapping("/api/emp")
@RefreshScope
@Api("员工管理")
public class EmpController {
    @Autowired
    private EmpService empService;
    @Autowired
    private StudentClient client;

    @ApiOperation("员工列表")
    @GetMapping("/list")
    public R list(){
        List<Emp> list = empService.list();
        return R.ok().data("list",list);
    }
    @ApiOperation("学生列表")
    @GetMapping("/student/list")
    public R studentList(){
        return client.list();
    }

    @ApiOperation("利用id查询学生")
    @GetMapping("/student/findById/{id}")
    public R studentById(@PathVariable @ApiParam(value = "学生id" ,required = true) Integer id){
        return client.findById(id);
    }

    //使用id查询学生 使用RestTemplate
    @ApiOperation("利用id查询学生使用RestTemplate")
    @GetMapping("/student/findById2/{id}")
    public R studentById2(@PathVariable @ApiParam(value = "学生id" ,required = true) Integer id){
        return empService.findStudentById(id);
    }
}
